package com.atguigu.gmall.alipay;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：MJS
 * @date ：Created in 2021/5/28  9:45
 * @description：TODO
 * 测试支付宝对外暴露的接口
 */
public class AlipayDemo {
    public static void main(String[] args) throws AlipayApiException {
        //支付宝的客户端
        AlipayClient alipayClient = new DefaultAlipayClient(
                 "https://openapi.alipaydev.com/gateway.do",
                 "2021000117665726",
                "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCydIKvHoK37wp1DLL5DY0RcGiMTzDKxqlVawKOogXCrC+X4Dn7PnDrM3b2oOcr/XjooWADW9DfLaK19lENfgE0n6Rjp06ExM71zPQ/dRSYPMUVT+vKOoVEWijUZeN9K8GZNYlcmyIcXkFv1DhDqS5wEYxPbvdzBA/pM/JD62lZxnHeyqd+JEsBSolx3Ux//NoQRPjV4+whlXjy7HRa4KfHb64etJhKvnj4wej3h+i6Wjpu527T2PclgXOiluAmctkj5mG412UmZhUBnC12ZXjBIaabRY4rloPgNQ0fGXYwTgEi4Ih8QWfJLR6W/Ukhs8ssQd4oLPuTxoydoWqgHGVTAgMBAAECggEBAJbj+RQFYlYQIvFxuWro0FzshRoOY50xeUCmaNUdnm1Kljt+9se/tk7Jh09mIdGKU0+wE7UDT4tF1QyypzoXTwGl8qPodXXBy5T+pY96ed13lNU+bIrkDIcNDPT66e2Or/XR1MGe0qrV79KUyLY9OOy9ibwogcaYqrNunuxbAwtKW+1K66bim5628K+pzmdOKpG9UH4/3mjWys03tHQR6xjDBarg6wRB8jrG7zAgunkHvZ/ojze9uTPmK+lx/pnkwgsYhpYzjeqg9r9zUfG1fTJ2yy5j/4y1ZU+O+dGoYf85NCQ1uPJh8NwuRiq8AlZhY36f/V5K4ttbtv7f5l5a5EECgYEA5Sa92FB/NlezIpzwTdI1HsgJAwxxprbeAq/gT5h8fQwln/b+YcNZARnMVOQAxA0Qjniw7KdhA1lOcISGL1tIJWErfDUUlTzCicRc60JewfF2sgB+dsNYakVvfzHuPPFzoMfgm7vE3+mfLa+1/xRtaOaJhOrG7UyatipctNqBOMMCgYEAx10qfdfwCe3jNKYkyGtKMcn59gK62D+XFDr14xXxV3wb1k1z3UT8wRdJk0R9Fn7NeuIIbPoQAMynpy0w1bJmB5K/GhyvGooihpu6+DoI2CET03A7wAtHeATglTtjzuQWY+DhnSACjcbaF3ush/3wRZx4+X+W7Xn8b+zy8+zU2DECgYAN+4o0C91nVHyizQ7AwOXq5eve2sCImrn7Uf4O/VADVV1qYGjvUDs7HPbh6zO8wstS1jx9hE0gJi/qH7wMYbaKSV6c6qRB4v4/59J/rIIZtYE3pV4SIyNfALOoAET4RQd4NRoYhqGhxCCpagJh+T4f24liqezPiBAcs4MKqhaefwKBgQCSB0gMjZMhcsIt2lSvCQd7mLoi3LUHmOyMwPNCttvkfN/XBTyNIu8QcIJQAKavR4ozLEWHrVLzgvR6m7tdjCL4ASFBeyk3g17uwjsdf0TjKrde9KKPdLOQ0eG+7ZWaAa/00M/xS3UTbEhrUwd5RSQtmQNznWVr5SJmyWTcDumIwQKBgC3c+46Wu4il3/Vbg+OZwYY76Ev37LicR02wXRJ6CThr0d5amNGEoHPAJvWFbXaZ1XNt5RE3U3CJypaq97qkO/eZ/MBsm/BjZgpulWjz52fFJfFSdLdZwmufM3ZLEl4LvLgPVu6LUrfp1izDvF5g1YJAI8aH/Sar6RWijp2njA9c",  //用来签名
                "json",
                "UTF-8"  ,
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAldA3wV4CGBiHEH6C3zd6wAx36JJNhHv0dAoarh5tl8tXmPDiLklwbuV1lYvoOes0FbaIrWVoel2gZv0JDru/xH544/iqPmu9I/8QkVO82Ip4nzOfosxizRRwY9ZZc+pywoZdUVYp4tlYYhYSDhYe7qzPCVFo2sNevVNdjtfd46cRy5KEynG39EeHb1sYeFwaiPfHxLzALUAp7nUMN/2Pu+aYB9+YdEx8eaXArLBVGuYEtmt9osK7NuuS4niDlkYRw/FbcClMsx1QgGjNzyGenwC9l/uDk4MDN5i/arf9grbABX/wuCPvgFK9GjhwrzsEN9H1s4H/eiKfH4btcllXyQIDAQAB",//用来加密 并不往上传
                "RSA2");
        //创建支付宝支付请求界面
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        Map<String,String>param=new HashMap<>();
        param.put("out_trade_no","weqwe");
        param.put("product_code","FAST_INSTANT_TRADE_PAY");
        param.put("total_amount","123.09");
        param.put("subject","测试一下");
        request.setBizContent(JSONObject.toJSONString(param));
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if(response.isSuccess()){
            System.out.println(response.getBody());
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
        /*
        * <form name="punchout_form" method="post" action="https://openapi.alipaydev.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&sign=geELl5yNcgZ3lx7eObOu4ZUwtwTecKSv7Gxh13jZD3EPnjuGkwcUs5X1mmBO5V9WkNA6MQFL4GKPSl3UwAwxaxWguq2gSUpcs1ZCjezYEOs9K%2BZvjBeHJozpcOebRJLV4qn8gZqO1VVOMSRgSajQMjXdWhN9CHbtWY8cqoNcepe7pyt4wSh5i9f6TYlodVH3CVXqriClq%2FZDFGGmu4VvIReYq73PHLgHI6zNmTamhoiIn8SOQr7KYBxrBmleikLx34OvmU7OGFN4g5znRhwp0A2%2FRQMIMM3KEXM4VeSV6GwI%2FaxrFIAZAkLyn4PsyjBEzqTUtbIsHJqKia0gZWFA%2Bg%3D%3D&version=1.0&app_id=2021000117665726&sign_type=RSA2&timestamp=2021-05-28+10%3A37%3A02&alipay_sdk=alipay-sdk-java-4.8.73.ALL&format=json">
            <input type="hidden" name="biz_content" value="{&quot;out_trade_no&quot;:&quot;weqwe&quot;,&quot;total_amount&quot;:&quot;123.09&quot;,&quot;subject&quot;:&quot;测试一下&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}">
            <input type="submit" value="立即支付" style="display:none" >
            </form>
            <script>document.forms[0].submit();</script>
        调用成功*/
    }
}
